<?php
$openid = $_POST['openid'];
if($openid == -1){
	$row['success'] = 0;
	echo json_encode($row);
	exit;
}
$a = rand(0,100);
$b = rand(0,100);
if($a != $b){
	$row['success'] = 0;
	echo json_encode($row);
	exit;
}
$db = @mysql_connect('218.244.143.217', 'root', 'zhuoxuhui!', true);
mysql_select_db('test', $db);
$table = 'hd_code';
$sql = 'select * from '.$table.' where openid = \''.$openid.'\' limit 1';
$res = mysql_query($sql, $db);
$row = mysql_fetch_array($res);
if($row){
	$row['success'] = 0;
	echo json_encode($row);
	exit;
}

$sql = 'select * from '.$table.' where openid = 0 and status=1 limit 1';
$res = mysql_query($sql, $db);
$rows = array();
$row = mysql_fetch_array($res);
$ins = 'update '.$table.' set openid = \''.$openid.'\',status=0 where id = '.$row['id'];
$re = mysql_query($ins, $db);
if($re){
	$row['success'] = 1;
	echo json_encode($row);
	exit;
}else{
	$row['success'] = 0;
	echo json_encode($row);
	exit;
}
